// Copyright 2022 Proyectos y Sistemas de Mantenimiento SL (eProsima).
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ------------------------------------------------------------------
// Modification history:
// feature: provide query interfaces
// feature: Split history as an independent common module
// feature: discovery support client and server
// ------------------------------------------------------------------

#ifndef EDDS_RTPS_BUILTIN_DISCOVERY_PARTICIPANT_SIMPLE__SIMPLEPDPENDPOINTS_HPP_
#define EDDS_RTPS_BUILTIN_DISCOVERY_PARTICIPANT_SIMPLE__SIMPLEPDPENDPOINTS_HPP_

#include <memory>

#include <edds/rtps/builtin/data/BuiltinEndpoints.hpp>

#include <edds/rtps/builtin/BuiltinReader.hpp>
#include <edds/rtps/builtin/BuiltinWriter.hpp>
#include <discovery/participant/PDPEndpoints.hpp>
#include <history/ITopicPayloadPool.h>
#include <edds/rtps/reader/StatelessReader.h>
#include <edds/rtps/writer/StatelessWriter.h>
#include <edds/dds/builtin/common/Types.hpp>

namespace evbs {
namespace ertps {
namespace rtps {

/**
 * Container for the builtin endpoints of PDPSimple
 */
struct SimplePDPEndpoints : public PDPEndpoints {
    ~SimplePDPEndpoints() override = default;

    BuiltinEndpointSet_t builtin_endpoints() const override {
        return DISC_BUILTIN_ENDPOINT_PARTICIPANT_ANNOUNCER | DISC_BUILTIN_ENDPOINT_PARTICIPANT_DETECTOR;
    }

    const std::unique_ptr<ReaderListener>& main_listener() const override { return reader.listener_; }

    bool enable_pdp_readers(RTPSParticipantImpl* participant) override {
        return participant->enableReader(reader.reader_);
    }

    void disable_pdp_readers(RTPSParticipantImpl* participant) override { participant->disableReader(reader.reader_); }

    void delete_pdp_endpoints(RTPSParticipantImpl* participant) override {
        participant->deleteUserEndpoint(writer.writer_->getGuid());
        participant->deleteUserEndpoint(reader.reader_->getGuid());
    }

    void remove_from_pdp_reader_history(const InstanceHandle_t& remote_participant) override {
        reader.remove_from_history(remote_participant);
    }

    void remove_from_pdp_reader_history(CacheChange_t* change) override { reader.history_->remove_change(change); }

    //! get is_send_multi
    bool getSendMulti() const { return writer.writer_->getSendMulti(); }

    //! set is_send_multi
    void setSendMulti(bool send_multi) { return writer.writer_->setSendMulti(send_multi); }

    //! Builtin Simple PDP reader
    BuiltinReader<StatelessReader> reader;

    //! Builtin Simple PDP writer
    BuiltinWriter<StatelessWriter> writer;
};

}  // namespace rtps
}  // namespace ertps
}  // namespace evbs

#endif  // EDDS_RTPS_BUILTIN_DISCOVERY_PARTICIPANT_SIMPLE__SIMPLEPDPENDPOINTS_HPP_
